#pragma once

#include "tcp_server.h"
#include <QObject>
#include <functional>
#include <thread>

class MavlinkServer : public QObject {
    Q_OBJECT

public:
    MavlinkServer(QObject *parent = nullptr);
    ~MavlinkServer();
    void start(const std::string& ip, uint16_t port);
    void set_mavlink_message_callback(TCPServer::MavlinkMessageCallback callback);
    void send_mavlink_message(const mavlink_message_t& message);

signals:
    void mavlinkMessageReceived(const mavlink_message_t& message);

private:
    std::shared_ptr<TCPServer> tcp_server_;
    std::shared_ptr<std::thread> thread_receive_;

    void receive_thread();
    bool running_{false};
};